<extend name='Index/index' />

<block name="main">
                <div class="bg-light lter b-b wrapper-md">
                    <h1 class="m-n font-thin h3">英雄详情管理</h1>
                </div>
                <div class="wrapper-md">
                    <div class="panel panel-default">
                        <div class="table-responsive">
                            <table class="table table-striped b-t b-light" style="table-layout: fixed;">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>英雄ID</th>
                                        <th>英雄名称</th>
                                        <th>技能1</th>
                                        <th>技能2</th>
                                        <th>技能3</th>
                                        <th>技能4</th>
                                        <th>技能1描述</th>
                                        <th>技能2描述</th>
                                        <th>技能3描述</th>
                                        <th>技能4描述</th>
                                        <th>英雄背景故事</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <volist name='data' id='s'>
                                    <tr>
                                        <td title="<{$s.s_id}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.s_id}></td>
                                        <td title="<{$s.c_id}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.c_id}></td>
                                        <td title="<{$s.h_name}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.h_name}></td>
                                        <td title="<{$s.s_name1}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.s_name1}></td>
                                        <td title="<{$s.s_name2}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.s_name2}></td>
                                        <td title="<{$s.s_name3}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.s_name3}></td>
                                        <td title="<{$s.s_name4}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.s_name4}></td>
                                        <td title="<{$s.s_detail1}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.s_detail1}></td>
                                        <td title="<{$s.s_detail2}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.s_detail2}></td>
                                        <td title="<{$s.s_detail3}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.s_detail3}></td>
                                        <td title="<{$s.s_detail4}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.s_detail4}></td>
                                        <td title="<{$s.s_bg}>" style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"><{$s.s_bg}></td>
                                        <td>
                                        <a   class='btn btn-info' data-toggle="modal" data-target="#myModal" > 编辑</a> 
                                        </td>
                                    </tr>
                                    </volist>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
<!-- 编辑英雄的模态框 -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" id="guanbi" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">编辑英雄</h4>
                </div>
                <div class="modal-body">
                    
                    <form class="form-horizontal" role="form" onsubmit="return false">
                        <div class="form-group">
                            <label for="inputEmail" class="col-sm-2 control-label">ID</label>
                            <div class="col-sm-9">
                                <input type="email" class="form-control" id="id" readonly="" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail" class="col-sm-2 control-label">c_id</label>
                            <div class="col-sm-9">
                                <input type="email" class="form-control" id="hid" readonly="" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail" class="col-sm-2 control-label">英雄名称</label>
                            <div class="col-sm-9">
                                <input type="email" class="form-control" id="name" readonly="" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能1</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="s1" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能2</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="s2" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能3</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="s3" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能4</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="s4" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能1描述</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="sd1" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能2描述</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="sd2" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能3描述</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="sd3" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能4描述</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="sd4" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label" >英雄背景</label>
                            <div class="col-sm-9">
                            <!-- <textarea name="" id="" cols="30" rows="10"></textarea> -->
                                <input type="text" class="form-control" id="bg" value="">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button id="close" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button id="save" type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>


<script type="text/javascript">
    $(function(){
        $("a:contains('编辑')").click(function(){
            var id = $(this).parents('tr').children('td').eq(0).html();
            var hid = $(this).parents('tr').children('td').eq(1).html();
            var name = $(this).parents('tr').children('td').eq(2).html();
            var s1 = $(this).parents('tr').children('td').eq(3).html();
            var s2 = $(this).parents('tr').children('td').eq(4).html();
            var s3 = $(this).parents('tr').children('td').eq(5).html();
            var s4 = $(this).parents('tr').children('td').eq(6).html();
            var sd1 = $(this).parents('tr').children('td').eq(7).html();
            var sd2 = $(this).parents('tr').children('td').eq(8).html();
            var sd3 = $(this).parents('tr').children('td').eq(9).html();
            var sd4 = $(this).parents('tr').children('td').eq(10).html();
            var bg = $(this).parents('tr').children('td').eq(11).html();
            $('#id').val(id);
            $('#hid').val(hid);
            $('#name').val(name);
            $('#s1').val(s1);
            $('#s2').val(s2);
            $('#s3').val(s3);
            $('#s4').val(s4);
            $('#sd1').val(sd1);
            $('#sd2').val(sd2);
            $('#sd3').val(sd3);
            $('#sd4').val(sd4);
            $('#bg').val(bg);
        })
            $('#save').click(function(){
                var id = $('#id').val();
                var hid = $('#hid').val();
                var name = $('#name').val();
                var s1 = $('#s1').val();
                var s2 = $('#s2').val();
                var s3 = $('#s3').val();
                var s4 = $('#s4').val();
                var sd1 = $('#sd1').val();
                var sd2 = $('#sd2').val();
                var sd3 = $('#sd3').val();
                var sd4 = $('#sd4').val();
                var bg = $('#bg').val();
                $.ajax({
                url:"<{:U('edit')}>",
                type:"POST",
                data:{'c_id':hid,'h_name':name,'s_name1':s1,'s_name2':s2,'s_name3':s3,'s_name4':s4,'s_detail1':sd1,'s_detail2':sd2,'s_detail3':sd3,'s_detail4':sd4,'s_bg':bg},
                dataType:'json', 
                success: function(data){
                    if(data==1){
                        alert('编辑成功');
                        $('#guanbi').click();
                        window.location.reload();
                    }
                    if(data == 0){
                        alert('未做修改');
                        return false
                    }
                }
                })
            })

            $("a:contains('删除')").click(function(){
                var id = $(this).parents('tr').children('td').eq(0).html();
                $(this).parents('tr').remove();
                $.ajax({
                url:"<{:U('d')}>",
                type:"POST",
                data:{'c_id':id},
                dataType:'json', 
                success: function(data){
                    if(data == 1){
                        alert('删除成功');
                    }else{
                        alert('删除失败');
                    }
                    }
                })
            })

            $('#add').click(function(){
                var id = '';
                var name = $('#addname').val();
                if(name==""){
                    alert('英雄名不能为空');
                    return false;
                }
                var src = $('#addsrc').val();
                if(src == ""){
                    alert('小头像地址不能为空');
                    return false;
                }
                var b_src = $('#addb_src').val();
                if(b_src == ""){
                    alert('英雄大头像地址不能为空');
                    return false;
                }
                var detail = $('#adddetail').val();
                if(detail == ""){
                    alert('英雄描述不能为空');
                    return false;
                }
                var type = $('#addtype').val();
                if(type == ""){
                    alert('英雄类型不能为空');
                    return false;
                }
                $.ajax({
                url:"<{:U('add')}>",
                type:"POST",
                data:{'c_id':id,'h_name':name,'h_name':src,'h_icon':src,'h_iconHover':b_src,'h_detail':detail,'h_type':type},
                dataType:'json', 
                success: function(data){
                    // console.log(data);
                    if(data > 0){
                        alert('添加成功');
                         window.location.reload();
                    }else{
                        alert('添加失败');
                        return false;
                    }
                    }
                })
            })
    })
</script>
</block>
